# !/usr/bin/python
# -- coding:utf8 --
# !/usr/bin/kivy
import os
import kivy
from kivy.app import App
from kivy.core.text import LabelBase
from kivy.core.window import Window
from kivy.factory import Factory
from kivy.resources import resource_add_path
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput

# kivy.require('1.0.6')

# 解决中文乱码问题
# 引入资源目录,如 fonts 目录位于项目根目录下，写相对路径(不要写绝对路径)相当于告诉kivy　HarmonyOS_Sans_SC_Regular.ttf 字体位于 fonts 目录中
resource_add_path(os.path.abspath('./fonts'))
# 替换kivy中的默认字体，使用我们的新字体
LabelBase.register('Roboto', 'HarmonyOS_Sans_SC_Regular.ttf')

# 测试时规定尺寸
# Window.size = (9*40, 16*40)


class Home(BoxLayout):
    def __init__(self, **kwargs):
        super(Home, self).__init__(**kwargs)
        self.orientation = "vertical"

        self.lblShow = Label(text="昜丿捺")
        self.lblShow.markup = True

        self.btnBlog = Button(text="博客", font_size=48, background_color=(1, 2, 3, 1),
                              color=(1, 1, 1, 1))
        self.btnBlog.bind(on_press=self.btnBlog_press)
        self.btnPWD = Button(text="密码", font_size=48, background_color=(3, 2, 1, 1))
        self.btnPWD.bind(on_press=self.btnPWD_press)
        box_layout1 = BoxLayout(orientation="horizontal")
        box_layout1.add_widget(self.btnBlog)
        box_layout1.add_widget(self.btnPWD)

        self.btnGift = Button(text="礼簿", font_size=48, background_color=(2, 0.1, 0.3, 1))
        self.btnBook = Button(text="账簿", font_size=48, background_color=(0.9, 0.5, 1.8, 1))
        box_layout2 = BoxLayout(orientation="horizontal")
        box_layout2.add_widget(self.btnGift)
        box_layout2.add_widget(self.btnBook)

        self.btnNote = Button(text="便签", font_size=48, background_color=(1.1, 1.7, 0.4, 1))
        self.btnTest = Button(text="试验", font_size=48, background_color=(2, 0.6, 0.9, 1))
        self.btnTest.bind(on_press=self.btnTest_press)
        box_layout3 = BoxLayout(orientation="horizontal")
        box_layout3.add_widget(self.btnNote)
        box_layout3.add_widget(self.btnTest)

        self.add_widget(self.lblShow)
        self.add_widget(box_layout1)
        self.add_widget(box_layout2)
        self.add_widget(box_layout3)

    def btnBlog_press(self, button_pressed):
        self.lblShow.text = "https://yangpiena.github.io/"

    def btnPWD_press(self, button_pressed):
        self.lblShow.text = "密码好像是123456"

    def btnTest_press(self, button_pressed):
        self.lblShow.text = "恭喜您，试验成功！"
        # 多页面切换教程：https://blog.csdn.net/cloveses/article/details/80385986


class MainApp(App):
    title = '昜丿捺'
    icon = 'icon.png'

    def build(self):
        return Home()

    def on_pause(self):
        return True


if __name__ == '__main__':
    MainApp().run()
